package com.ebelter.btcomlib.utils;

import android.text.TextUtils;

import com.ebelter.btcomlib.CommonLib;
import com.ebelter.btcomlib.R;
import com.ebelter.btcomlib.models.beans.ScaleUser;
import com.ebelter.btcomlib.models.bluetooth.products.scale.bean.ScaleMeasureResult;

import java.util.Calendar;



public class CommonUtils {
    //字符串 2014-01-22 截取整数
    public static int getBirthdayIntValue(String string,int index,int defaultValue){
        if (TextUtils.isEmpty(string)){
            return defaultValue;
        }
        String[] args = string.split("-");
        if (args.length!=3){
            return defaultValue;
        }
        return NumUtils.string2Int(args[index],defaultValue);
    }

    //获取年龄
    public static int getAgeByBirthday(int year){
        Calendar calendar = Calendar.getInstance();
        return calendar.get(Calendar.YEAR)-year;
    }


    public static ScaleMeasureResult dealScaleMeasureResult(ScaleMeasureResult result) {

        if (result.fat<0){
            result.fat=0;
        }
        if (result.weight<0){
            result.weight=0;
        }
        if (result.muscleVolume<0){
            result.muscleVolume=0;
        }

        if (result.boneVolume<0){
            result.boneVolume=0;
        }
        if (result.skeletalMuscle<0){
            result.skeletalMuscle=0;
        }

        if (result.bmr<0){
            result.bmr=0;
        }
        if (result.visceralFat<0){
            result.visceralFat=0;
        }
        if (result.waterRate<0){
            result.waterRate=0;
        }
        if (result.protein<0){
            result.protein=0;
        }

        if (ScaleUser.getUser().getAge()<18){
            result.fat=0;
            result.muscleVolume=0;
            result.boneVolume=0;
            result.skeletalMuscle=0;
            result.bmr=0;
            result.visceralFat=0;
            result.waterRate=0;
            result.protein=0;
        }

        return result;
    }




    public static String getMonths(int month){

        if (month>=1&&month<=12){
            String[] months = CommonLib.APPContext.getResources().getStringArray(R.array.months);

            return months[month-1];

        }

        return month+"";

    }
}
